package com.tudouji.project.product.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.product.domain.Productinfo;
import com.tudouji.project.product.service.IProductinfoService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 商品管理Controller
 * 
 * @author wf
 * @date 2020-12-28
 */
@RestController
@RequestMapping("/product/productinfo")
public class ProductinfoController extends BaseController
{
    @Autowired
    private IProductinfoService productinfoService;

    /**
     * 查询商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Productinfo productinfo)
    {
        startPage();
        List<Productinfo> list = productinfoService.selectProductinfoList(productinfo);
        return getDataTable(list);
    }

    /**
     * 导出商品管理列表
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:export')")
    @Log(title = "商品管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Productinfo productinfo)
    {
        List<Productinfo> list = productinfoService.selectProductinfoList(productinfo);
        ExcelUtil<Productinfo> util = new ExcelUtil<Productinfo>(Productinfo.class);
        return util.exportExcel(list, "productinfo");
    }

    /**
     * 获取商品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(productinfoService.selectProductinfoById(guid));
    }

    /**
     * 新增商品管理
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:add')")
    @Log(title = "商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Productinfo productinfo)
    {
        return toAjax(productinfoService.insertProductinfo(productinfo));
    }

    /**
     * 修改商品管理
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:edit')")
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Productinfo productinfo)
    {
        return toAjax(productinfoService.updateProductinfo(productinfo));
    }

    /**
     * 删除商品管理
     */
    @PreAuthorize("@ss.hasPermi('product:productinfo:remove')")
    @Log(title = "商品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(productinfoService.deleteProductinfoByIds(guids));
    }


    /**
     * 查询商品管理列表
     */
    @GetMapping("/findProductList")
    public AjaxResult findProductList(Productinfo productinfo)
    {
        List<Productinfo> list = productinfoService.selectProductinfoList(productinfo);
        return AjaxResult.success(list);
    }
}
